﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class InvTransBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IInvTransDA InvTrans = DataAccess.CreateInvTransDA();
        private PubParasInfo pubParasInfo;

        public InvTransBLL()
        {
            this.pubParasInfo = null;
        }

        public InvTransBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public InvTransBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public DataSet GetAllInvTransInfo()
        {
            return InvTrans.GetAllInvTrans(this.dataBaseID[0], this.pubParasInfo);
        }

        public InvTransInfo GetInfoByID(string areaID)
        {
            return InvTrans.GetInvTransByID(areaID, this.dataBaseID[0], this.pubParasInfo);
        }

        public DataSet GetInfoByInvTransQueryEntity(InvTransQueryEntity TransQuery)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(TransQuery.TransID))
            {
                sqlWhere.Add(" IT.TRANS_ID " + TransQuery.TransID);
            }
            if (!string.IsNullOrEmpty(TransQuery.CreatedDate))
            {
                sqlWhere.Add(TransQuery.CreatedDate.Replace("@CreatedDate@", "  IT.TRANS_DATE "));
            }
            if (!string.IsNullOrEmpty(TransQuery.TransType))
            {
                sqlWhere.Add(" IT.TRANS_TYPE " + TransQuery.TransType);
            }
            if (!string.IsNullOrEmpty(TransQuery.SourceTransType))
            {
                sqlWhere.Add(" IT.SOURCE_TRANS_TYPE " + TransQuery.SourceTransType);
            }
            if (!string.IsNullOrEmpty(TransQuery.Lot))
            {
                sqlWhere.Add(" IT.LOT " + TransQuery.Lot);
            }
            if (!string.IsNullOrEmpty(TransQuery.VendorID))
            {
                sqlWhere.Add(" IT.VENDOR_ID " + TransQuery.VendorID);
            }
            if (!string.IsNullOrEmpty(TransQuery.OwnerID))
            {
                sqlWhere.Add(" IT.OWNER_ID " + TransQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(TransQuery.SkuID))
            {
                sqlWhere.Add(" IT.SKU_ID " + TransQuery.SkuID);
            }
            if (!string.IsNullOrEmpty(TransQuery.FromLoc))
            {
                sqlWhere.Add(" IT.FROM_LOC " + TransQuery.FromLoc);
            }
            if (!string.IsNullOrEmpty(TransQuery.ToLoc))
            {
                sqlWhere.Add(" IT.TO_LOC " + TransQuery.ToLoc);
            }
            if (!string.IsNullOrEmpty(TransQuery.FromLpnID))
            {
                sqlWhere.Add(" IT.FROM_LPN_ID " + TransQuery.FromLpnID);
            }
            if (!string.IsNullOrEmpty(TransQuery.ToLpnID))
            {
                sqlWhere.Add(" IT.TO_LPN_ID " + TransQuery.ToLpnID);
            }
            if (!string.IsNullOrEmpty(TransQuery.CreatedBy))
            {
                sqlWhere.Add(" IT.CREATED_BY " + TransQuery.CreatedBy);
            }
            if (!string.IsNullOrEmpty(TransQuery.Qty))
            {
                sqlWhere.Add(" IT.QTY " + TransQuery.Qty);
            }
            if (!string.IsNullOrEmpty(TransQuery.DocID))
            {
                sqlWhere.Add(" IT.DOC_ID " + TransQuery.DocID);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr01))
            {
                sqlWhere.Add(" IT.LOT_ATTR01 " + TransQuery.LotAttr01);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr02))
            {
                sqlWhere.Add(" IT.LOT_ATTR02 " + TransQuery.LotAttr02);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr03))
            {
                sqlWhere.Add(" IT.LOT_ATTR03 " + TransQuery.LotAttr03);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr04))
            {
                sqlWhere.Add(" IT.LOT_ATTR04 " + TransQuery.LotAttr04);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr05))
            {
                sqlWhere.Add(" IT.LOT_ATTR05 " + TransQuery.LotAttr05);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr06))
            {
                sqlWhere.Add(" IT.LOT_ATTR06 " + TransQuery.LotAttr06);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr07))
            {
                sqlWhere.Add(" IT.LOT_ATTR07 " + TransQuery.LotAttr07);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr08))
            {
                sqlWhere.Add(" IT.LOT_ATTR08 " + TransQuery.LotAttr08);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr09))
            {
                sqlWhere.Add(" IT.LOT_ATTR09 " + TransQuery.LotAttr09);
            }
            if (!string.IsNullOrEmpty(TransQuery.LotAttr10))
            {
                sqlWhere.Add(" IT.LOT_ATTR10 " + TransQuery.LotAttr10);
            }
            if (!string.IsNullOrEmpty(TransQuery.ExternalLot))
            {
                sqlWhere.Add(" IT.EXTERNAL_LOT " + TransQuery.ExternalLot);
            }
            if (!string.IsNullOrEmpty(TransQuery.ReceiptDate))
            {
                sqlWhere.Add(TransQuery.ReceiptDate.Replace("@ReceiptDate@", " RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(TransQuery.ProduceDate))
            {
                sqlWhere.Add(" IT.PRODUCE_DATE " + TransQuery.ProduceDate);
            }
            if (!string.IsNullOrEmpty(TransQuery.ExpiryDate))
            {
                sqlWhere.Add(" IT.EXPIRY_DATE " + TransQuery.ExpiryDate);
            }
            return InvTrans.GetInvTransByQueryList(sqlWhere, TransQuery, this.dataBaseID[0], this.pubParasInfo);
        }
    }
}

